package com.kws.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.kws.common.core.domain.R;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.system.api.domain.Rq.CreateDeliverAddressRq;
import com.kws.system.domain.SysDeliveryAddress;
import com.kws.system.domain.info.QueryDeliveryAddressInfo;
import com.kws.system.domain.vo.UpdateDeliveryAddressRq;
import com.kws.system.service.SysDeliveryAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b>SysDeliveryAddressController</b>
 *
 * @description: SysDeliveryAddressController <br>
 * @date: 2024/11/6 15:32 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "收货地址管理模块")
@RestController
public class SysDeliveryAddressController {
    private static final Logger logger = LoggerFactory.getLogger(SysDeliveryAddressController.class);

    @Autowired
    private SysDeliveryAddressService sysDeliveryAddressService;

    @ApiOperation("分页查询收货地址管理列表")
    @GetMapping("/query/deliveryAddress/page")
    public R<Page<QueryDeliveryAddressInfo>> queryDeliveryAddressPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                      @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                      @RequestParam(required = false) String consigneeName){
        Page<QueryDeliveryAddressInfo> pageInfo = sysDeliveryAddressService.queryDeliveryAddressPage(pageNum,pageSize,consigneeName);
        return R.ok(pageInfo);
    }

    @ApiOperation("新增收货地址")
    @PostMapping("/create/deliverAddress")
    public R createDeliverAddress(@RequestBody CreateDeliverAddressRq rq){
        boolean status = sysDeliveryAddressService.createDeliverAddress(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID查询收货地址详情")
    @GetMapping("/query/deliverAddress/byId")
    public R<QueryDeliveryAddressInfo> queryDeliveryAddressById(@RequestParam Long id){
        QueryDeliveryAddressInfo info = sysDeliveryAddressService.queryDeliveryAddressById(id);
        return R.ok(info);
    }

    @ApiOperation("根据ID修改收货地址信息")
    @Log(title = "修改收货地址信息", businessType = BusinessType.UPDATE)
    @PostMapping("/update/deliverAddress")
    public R updateDeliveryAddress(@RequestBody UpdateDeliveryAddressRq rq){
        boolean status = sysDeliveryAddressService.updateDeliveryAddress(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID删除收货地址信息")
    @Log(title = "删除收货地址信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/deliverAddress/byId")
    public R deleteDeliveryAddressById(@RequestParam Long id){
        boolean status = sysDeliveryAddressService.deleteDeliveryAddressById(id);
        return R.ok(status);
    }
}
